<?php

namespace App\Model;


use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class Turntable extends BaseModel
{
    protected $connection = 'api';
    protected $table = 'table';
    protected $table_poll = 'table_poll';


    public function getList($input = [])
    {
        $limit = $input['limit'] ?? 10;
        $res = DB::connection($this->connection)->table($this->table)
            ->paginate($limit);
        return $this->objToArray($res);
    }

    /**
     * 创建或更新
     * prop_id 存在则更新，不存在则新增
     * @param $data
     * @return mixed
     */
    public function createOrUpdateData($data)
    {
        return curl_request(getKkaudioApiUrl() . '/inner/table/upsert', $data, 'json', 'POST');
    }

    public function getPollList($table_id)
    {
        $res = DB::connection($this->connection)->table($this->table_poll)->where(['table_id' =>$table_id])->get();
        return $this->objToArray($res);
    }

    public function addTurntablePoll($data){
        return curl_request(getKkaudioApiUrl() . '/inner/table/poll/upsert', $data, 'json', 'POST');
    }

}
